/*
*Data
*chenjie
*2012-5-4
*/
package com.data
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class Data
	{
		public static var playerWidth:int=800
		public static var playerHeight:int=600
			
		public static var swfWidth:int=800
		public static var swfHeight:int=600
		
		public static var playArr:Array=[]
		public static var btnBitmapDataArr:Array=[]
			
		public static var adTime:int	
		
		public static var swfUrl:String
		public static var playUrl:String
		public static var htmlUrl:String
		
		
		public static const XML:String="xml"
		public static const JS:String="js"
		public static const URL:String="url"
			
		public static var index:int=0	
			
		public static var re:Number=4/3	
		
		public function Data()
		{
		}
		
		public static function initBitmapDataArr(dis:DisplayObject):void{
			var sourceBitmapData:BitmapData=new BitmapData(dis.width,dis.height)
			sourceBitmapData.draw(dis)
				
			var tempRectangle:Rectangle = new Rectangle(0, 0, 32, 32);  
			var tPoint:Point = new Point(0, 0);
			
		   for(var i:int=1;i<=dis.height;i++){
		      if(i %32==0 && i != dis.height){
				  tempRectangle.y=i
				  var bitmapData:BitmapData=new BitmapData(32,32,false,0x000000)
				  bitmapData.copyPixels(sourceBitmapData,tempRectangle,tPoint)
				  btnBitmapDataArr.push(bitmapData)  
			  }
		   }
		}
		
		public static function insertPlayModel(playModel:PlayModel,type:String):void{
			playArr.push(playModel)
			playModel.source=type
				
			if(playModel.name=="content"){
				index++
			}	
				
			for(var i:int=0;i<playArr.length;i++){
				for(var j:int=0;j<playArr.length;j++){
					var temp:PlayModel
					if(playArr[i].name=="content" && playArr[j].name){
						if(playArr[i].name.length < playArr[j].name.length){
							temp=playArr[j]
							playArr[j]=playArr[i]
							playArr[i]=temp
						}
					}
				}
			}	
			
			if(index>1){
				for(var k:int=0;k<playArr.length;k++){
					var temp2:PlayModel=playArr[k]
					if(temp2.name=="content"){
						if(temp2.source==URL){
							deletePlayModel(XML);
							deletePlayModel(JS);
						} 
						if(temp2.source==JS){
							deletePlayModel(XML);
						}
					}
				}	
			}
			for(var y:int=0;y<playArr.length;y++){
				var temp3:PlayModel=playArr[y]
				trace(temp3.name+" "+temp3.source)	
			}	
			trace(" ####### ")	
		}
		
		public static function deletePlayModel(name:String):void{
			for(var y:int=0;y<playArr.length;y++){
				var temp3:PlayModel=playArr[y]
					if(temp3.source==name){
						playArr.splice(y,1)
					} 
			}
		}
		
	}
}